<template>
  <view>
     <view v-for="(item ,index) in goodInfo" :key="index" class="goodsItem" @click="gotpdetail(item)">

      <view class="goodsleft">
        <image  :src="item.goods_small_logo||defaultPic"></image>
      </view>
      <view class="goodRight">
        <text>{{item.goods_name}}</text>
        <text>￥{{item.goods_price | tofixed}}</text>
      </view>
    
</view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
                defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
        queryObj:{
          query:'',
          cid:'',
          pagenum: 1,
         pagesize: 10
        },
        isloading:false,
        total:0,
        goodInfo:[]
       
      };
    },
    filters:{
      tofixed(num){
        return Number(num).toFixed(2)
      }
    },
    onLoad(options){
 this.queryObj.query=options.query||''
 this.queryObj.query=options.cid||''
 this.getgoodInfo()
    },
    methods:{
 async     getgoodInfo(cb){
   this.isloading=true
 const result=await uni.$http. reqgoodsInfo(this.queryObj)
      if(result.statusCode!==200) return uni.$showmsg()
      
      this.goodInfo=[...this.goodInfo,...result.data.message.goods]
      this.total=result.data.message.total
      this.isloading=false
      cb&&cb()
      },
    gotpdetail(item){
      uni.navigateTo({
        url:'../goods_detail/goods_detail?goods_id='+item.goods_id
      })
    }
     
      
    },
    onReachBottom(){
      if(this.queryObj.pagenum*this.queryObj.pagesize>this.total)
      return uni.$showmsg('已到最底部')
      if(this.isloading)
      return
      this.getgoodInfo()
    },
    onPullDownRefresh(){
      this.queryObj.pagenum=1
      this.goodInfo=[]
      this.total=0
      this.isloading=false
      this.getgoodInfo(()=>{
        uni.stopPullDownRefresh()
      })
      
      
    }
  }
</script>

<style lang="scss">
.goodsItem{
  display: flex;
  padding: 10px;
  .goodsleft{
    image{
      width:100px;
      height: 100px;
      padding-right: 5px;
      display: block;
    }
  }
  .goodRight{
    display: flex;
    flex-direction: column;
    
    justify-content:space-around;
    font-size: 13px;
    text:last-child{
       color: #c00000;
    }
  }
  }
</style>
